package com.hxd.pojo;
import java.util.ArrayList;
import java.util.List;

public class Page<T> {
    private int pagenum;//当前页面
    private int pageStartIndex;//当前页的起始索引
    private int pageSiae;//页面大小
    private int totalRows;//总记录数
    private int totalPages;//总页码
    private List<T> dates;//当前页所包含的数据

    public Page() {
        this.pagenum = 1;
        this.pageSiae = 6;
        dates = new ArrayList<>();
    }

    public int getPagenum() {
        return pagenum;
    }

    public void setPagenum(int pagenum) {
        this.pagenum = pagenum;
    }

    public int getPageStartIndex() {
        return (pagenum - 1) * pageSiae;
    }

    public void setPageStartIndex(int pageStartIndex) {
        this.pageStartIndex = pageStartIndex;
    }

    public int getPageSiae() {
        return pageSiae;
    }

    public void setPageSiae(int pageSiae) {
        this.pageSiae = pageSiae;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public int getTotalPages() {
        if(totalRows%pageSiae == 0){
            totalPages = totalRows/pageSiae;
        }else{
            totalPages = totalRows/pageSiae+1;
        }
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getDates() {
        return dates;
    }

    public void setDates(List<T> dates) {
        this.dates = dates;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pagenum=" + pagenum +
                ", pageStartIndex=" + pageStartIndex +
                ", pageSiae=" + pageSiae +
                ", totalRows=" + totalRows +
                ", totalPages=" + totalPages +
                ", dates=" + dates +
                '}';
    }
}
